﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MessageRouter.ServiceBroker
{
    internal sealed class ServiceBrokerEndpointAddress
    {
        private readonly string serverName;
        private readonly string instanceName;
        private readonly string databaseName;
        private readonly string schemaName;
        private readonly string queueName;

        public ServiceBrokerEndpointAddress(Uri address)
        {
            this.serverName = address.GetComponents(UriComponents.Host, UriFormat.Unescaped);
            string[] path = address.GetComponents(UriComponents.Path, UriFormat.Unescaped).Split('/');
            this.instanceName = path[0];
            this.databaseName = path[1];
            this.schemaName = path[2];
            this.queueName = path[3];
        }

        public string ServerName
        {
            get { return this.serverName; }
        }

        public string InstanceName
        {
            get { return this.instanceName; }
        }

        public string DatabaseName
        {
            get { return this.databaseName; }
        }

        public string SchemaName
        {
            get { return this.schemaName; }
        }

        public string QueueName
        {
            get { return this.queueName; }
        }
    }
}
